package com.franklin.validation.tool.annotations.spring;

import com.franklin.validation.tool.annotations.BaseAnnotation;

/**
 * Description :
 * Create By: Franklin
 * Date : 2020/6/19 14:37
 */
public enum RequestMethodAnnotations implements BaseAnnotation {
    REQUEST_MAPPING("org.springframework.web.bind.annotation.RequestMapping", (String)null),
    GET_MAPPING("org.springframework.web.bind.annotation.GetMapping", "GET"),
    POST_MAPPING("org.springframework.web.bind.annotation.PostMapping", "POST"),
    PUT_MAPPING("org.springframework.web.bind.annotation.PutMapping", "PUT"),
    DELETE_MAPPING("org.springframework.web.bind.annotation.DeleteMapping", "DELETE"),
    PATCH_MAPPING("org.springframework.web.bind.annotation.PatchMapping", "PATCH");

    private String qualifiedName;
    private String methodName;

    RequestMethodAnnotations(String qualifiedName, String methodName) {
        this.qualifiedName = qualifiedName;
        this.methodName = methodName;
    }

    @Override
    public String getQualifiedName() {
        return this.qualifiedName;
    }

    @Override
    public String getShortName() {
        return this.qualifiedName.substring(this.qualifiedName.lastIndexOf(".") - 1);
    }

    public String getMethodName() {
        return methodName;
    }

    public static RequestMethodAnnotations getByQualifiedName(String qualifiedName){
        for (RequestMethodAnnotations annotation : values()) {
            if (annotation.qualifiedName.equals(qualifiedName)){
                return annotation;
            }
        }
        return null;
    }

    public static RequestMethodAnnotations getByShortName(String shortName){
        for (RequestMethodAnnotations annotation : values()) {
            if (annotation.getQualifiedName().endsWith(shortName)){
                return annotation;
            }
        }
        return null;
    }
}
